<% title_tag @topic.title %>

<% content_for :scripts do %>
  <script type="text/javascript">
    Topics.topic_id = <%= @topic.id %>;
    <% if current_user && !@user_liked_reply_ids.blank? %>
    Topics.user_liked_reply_ids = [<%= @user_liked_reply_ids.join(",") %>];
    <% end %>
    $(document).ready(function(){
      <% if admin? %>
        $("#replies .reply a.edit").css('display','inline-block');
      <% elsif current_user %>
        $("#replies .reply a.edit[data-uid='<%= current_user.id %>']").css('display','inline-block');
      <% end %>
    })
  </script>
<% end %>

<div class="row">
  <div class="col-md-9">
    <div class="topic-detail panel panel-default">
      <%= render partial: "topics/topic_info", locals: { topic: @topic } %>

      <% if @topic.excellent? %>
        <div class="label-awesome">
          <i class="fa fa-diamond awesome"></i> 本帖已被设为精华帖！
          <% if admin? %>
          <div class="pull-right">
            <%= link_to icon_tag("close"), action_topic_path(@topic.id, type: 'unexcellent'), data: { method: "post", remote: true } %>
          </div>
          <% end %>
        </div>
      <% end %>

      <div class="panel-body markdown">
        <%= raw Setting.before_topic_html %>

        <article>
          <%= raw @topic.body_html %>
        </article>


        <%= raw Setting.after_topic_html %>
      </div>

      <div class="panel-footer clearfix">
        <%= render "buttons" %>
      </div>
    </div>

    <%= render partial: "ban_reason" %>

  <% if @replies.blank? %>
    <div class="no-result">
      <%= t("topics.no_replies") %>
    </div>
    <% else %>
    <div id="replies" class="panel panel-default" data-last-floor="<%= @replies.count(:all) %>">
      <div class="total panel-heading hide-ios">
        共收到 <b><%= @topic.replies_count %></b> 条回复
      </div>
      <div class="items panel-body">
        <%= cache([@topic, "raw:#{@show_raw}"]) do %>
          <%= render partial: "/replies/reply", collection: @replies %>
        <% end %>
      </div>
    </div>
  <% end %>

  <% if current_user %>
    <% if @topic.closed? %>
      <div class="alert alert-info">此话题已经于 <%= l @topic.closed_at, format: :long %> 关闭，不再接受任何回帖。</div>
    <% else %>
      <div id="reply" class="panel panel-default">
        <div class="panel-heading hide-ios">回帖</div>
        <div class="panel-body">
        <% if can? :create, Reply %>
          <%= render 'reply_form' %>
        <% else %>
          <div class="alert alert-info">
            当前设置新手用户不能在 22:00 ~ 9:00 发帖。
          </div>
        <% end %>
        </div>
      </div>
    <% end %>
  <% else %>
    <div class="panel panel-default">
      <div class="panel-body">
        <%= render partial: "topics/translation/need_login_to_reply" %>
      </div>
    </div>
  <% end %>

  <%= render 'related_topics' %>
</div>

<% if !mobile? %>
  <div class="sidebar hidden-mobile col-md-3">
    <%= render 'topic_sidebar' %>
  </div>
<% end %>
</div>
